package com.cloud.screen.api.service.impl;

import com.cloud.screen.api.entity.ScreenReqInfo;
import com.cloud.screen.api.entity.UnitInfo;
import com.cloud.screen.api.entity.UnitPower;
import com.cloud.screen.api.mapper.UnitInfoMapper;
import com.cloud.screen.api.service.PerformService;
import com.cloud.screen.api.service.PunishService;
import com.cloud.screen.common.utils.DateHelper;
import com.cloud.screen.interfaces.FeignClientForce;
import com.cloud.screen.interfaces.FeignClientPunish;
import com.cloud.screen.interfaces.FeignClientSystem;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: quokka-server
 * @description: PerformServiceImpl
 * @author: sl
 * @create: 2019-08-02 17:46
 **/
@Service
@Transactional
public class PerformServiceImpl implements PerformService {

    @Autowired
    private UnitInfoMapper unitInfoMapper;

    @Autowired
    private FeignClientPunish feignClientPunish;

    @Autowired
    private FeignClientSystem feignClientSystem;

    @Autowired
    private FeignClientForce feignClientForce;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private PunishService punishService;

    private static final Integer SELECT_DAY = 2;
    private static final Integer SELECT_WEEK = 3;
    private static final Integer SELECT_MONTH = 4;
    /**
     * 履职情况区域分布
     * @param start 开始时间
     * @param end 结束时间
     * @param regionid 区域ID
     * @param recType
     * @return
     */
    @Override
    public Map<String, Object> getPerformCaseRegion(String start, String end, Long regionid, Integer recType) {
        //分regionCode 查询各区域职权条数 和法律法规code
        UnitInfo unit = unitInfoMapper.selectByPrimaryKey(regionid == null?1:regionid);
        Map<String, Object> returnList = new HashMap<>();
        if (unit == null){
            return returnList;
        }
        List<Map<String, Object>> unitInfos =  feignClientSystem.getUnitInfoForProvince(regionid == null?1:regionid);
        //已履行职权信息(统计类别为行政处罚、行政强制)
        String powerFulfilSql = "SELECT rp.subject_id AS  unit_id,rc.punish_basis_code FROM  punish.rec_punish rp LEFT JOIN punish.rec_cause rc ON rp.rec_id = rc.rec_id  WHERE  " +
                "rc.punish_basis_code IN (SELECT  punish_basis_code FROM(  SELECT t1.unit_name,t2.punish_basis_code,t1.unit_id,t3.unit_code  FROM unit_power t1,  " +
                "(SELECT power_id,  punish_basis_code FROM  power_basis  WHERE  cause_id IS NOT NULL  GROUP BY  punish_basis_code  ) t2,  unit_info t3 WHERE  t1.power_id = t2.power_id AND t3.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "  AND t1.power_type_id = '02'  AND t3.unit_id = t1.unit_id  ) t ORDER BY punish_basis_code)  " +
                " AND rp.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "GROUP BY rp.unit_id,rc.punish_basis_code";
        List<UnitPower> list = jdbcTemplate.query(powerFulfilSql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> punishGroup = list.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        // 取出所有unit_id
        List<Long> unitIdList = list.stream().map(UnitPower::getUnitId).distinct().collect(Collectors.toList());
        String filter = "AND up.unit_id in  ('" + StringUtils.join(unitIdList, "','") + "')";
        String unitCodeFilter;
        if (!unit.getUnitCode().equals("/1/")) {
            unitCodeFilter = " ui.region_code";
        } else {
            unitCodeFilter = " LEFT (ui.region_code, 4) AS region_code";
        }
        String sql = "SELECT up.unit_id,pb.punish_basis_code,"+unitCodeFilter+" FROM unit_power up  LEFT JOIN power_basis pb ON up.power_id = pb.power_id  LEFT JOIN unit_info ui ON up.unit_id = ui.unit_id WHERE pb.cause_id IS NOT NULL  AND up.power_type_id = '02' "+filter+" GROUP BY up.unit_id,pb.punish_basis_code ORDER BY up.unit_id DESC";
        List<UnitPower> powers = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> powerGroup = powers.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        List<Map<String,Object>> unitPowers = new ArrayList<>();
        punishGroup.forEach((k, v) -> {
            powerGroup.forEach((p, g) -> {
                if (k.equals(p)) {
                    List<Map<String, Object>> list3 = v.stream()
                            .map(map -> g.stream()
                                    .filter(m -> Objects.equals(m.getPunishBasisCode(), map.getPunishBasisCode()))
                                    .findFirst().map(m -> {
                                        Map<String,Object> objectMap = new HashMap<>();
                                        objectMap.put("region_code",m.getRegionCode());
                                        objectMap.put("unit_id",map.getUnitId());
                                        objectMap.put("count",1);
                                        return objectMap;
                                    }).orElse(null))
                            .filter(Objects::nonNull).collect(Collectors.toList());
                    unitPowers.addAll(list3);
                }
            });
        });
        if ( unitInfos != null){
            unitInfos.addAll(unitPowers);
            List<Map<String, Object>> result = unitInfos.stream().collect(Collectors.groupingBy(e -> e.get("region_code")))
                    .entrySet().stream().map(e -> {
                        Map<String, Object> map = new HashMap<>();
                        map.put("seniorid", e.getValue().get(0).get("senior_id"));
                        map.put("regionid", e.getValue().get(0).get("unit_id"));
                        map.put("regionname", e.getValue().get(0).get("unit_name"));
                        final Integer[] i = {0};
                        if (e.getValue().size()>1){
                           e.getValue().forEach(v->{
                                i[0] += v.get("count")==null?0:Integer.parseInt(v.get("count").toString());
                           });
                            map.put("sumnum", i[0]);
                        }else {
                            map.put("sumnum", 0);
                        }
                        map.put("regioncode", regionIdFormat(e.getKey().toString()));
                        return map;
                    }).collect(Collectors.toList());
            UnitInfo unitInfo = getRegionInfo(unit.getRegionCode());
            //封装返回格式
            final int[] i = {0};
            result.forEach(sun -> {
                i[0] += Integer.parseInt(sun.get("sumnum")==null?"0":sun.get("sumnum").toString());
            });
            Map<String, Object> statMap = new HashMap<>();
            Map<String, Object> regionMap = new HashMap<>();
            regionMap.put("regionid", unitInfo.getUnitId());
            regionMap.put("regioncode", regionIdFormat(unitInfo.getRegionCode()));
            regionMap.put("regionname", unitInfo.getUnitName());
            regionMap.put("sumnum", i[0]);
            regionMap.put("seniorid", unitInfo.getSeniorId());
            statMap.put("region", regionMap);
            statMap.put("children", result);
            returnList.put("stat", statMap);
        }
        return returnList;
    }

    @Override
    public Map<String, Object> getPerformSummary(String start, String end, Long regionid, Integer recType) {
        UnitInfo unit = unitInfoMapper.selectByPrimaryKey(regionid == null?1:regionid);
        Map<String, Object> returnMap = new HashMap<>();
        if (unit == null){
            return returnMap;
        }
        //总职权信息
        String powerSql = "SELECT count(*) AS `authority` FROM unit_power ui LEFT JOIN unit_info uf ON ui.unit_id = uf.unit_id WHERE uf.delete_flag != 1 AND uf.unit_code like '" +  unit.getUnitCode() + "%' ";
        Integer powerCount = jdbcTemplate.queryForObject(powerSql, Integer.class);
        //已履行职权信息(统计类别为行政处罚、行政强制)
        // 取出所有行政处罚中 已被关联的 unit_id 和punish_basis_code 并根据unit_id  和punish_basis_code 分组
        // 取出所有unit_id 为上述list中，且 类型为行政处罚的所有已被关联的职权的 unit_id 和punish_basis_code 并根据unit_id  和punish_basis_code 分组
        // 已被关联的所有机构的职权 存在于行政处罚中的数量 定义为履职数量
        String powerFulfilSql = "SELECT rp.subject_id AS  unit_id,rc.punish_basis_code FROM  punish.rec_punish rp LEFT JOIN punish.rec_cause rc ON rp.rec_id = rc.rec_id  WHERE  " +
                "rc.punish_basis_code IN (SELECT  punish_basis_code FROM(  SELECT t1.unit_name,t2.punish_basis_code,t1.unit_id,t3.unit_code  FROM unit_power t1,  " +
                "(SELECT power_id,  punish_basis_code FROM  power_basis  WHERE  cause_id IS NOT NULL  GROUP BY  punish_basis_code  ) t2,  unit_info t3 WHERE  t1.power_id = t2.power_id AND t3.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "  AND t1.power_type_id = '02'  AND t3.unit_id = t1.unit_id  ) t ORDER BY punish_basis_code)  " +
                " AND rp.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "GROUP BY rp.unit_id,rc.punish_basis_code";
        List<UnitPower> list = jdbcTemplate.query(powerFulfilSql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> punishGroup = list.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        // 取出所有unit_id
        List<Long> unitIdList = list.stream().map(UnitPower::getUnitId).distinct().collect(Collectors.toList());
        String filter = "AND up.unit_id in  ('" + StringUtils.join(unitIdList, "','") + "')";
        String sql = "SELECT up.unit_id,pb.punish_basis_code FROM unit_power up  LEFT JOIN power_basis pb ON up.power_id = pb.power_id  WHERE pb.cause_id IS NOT NULL  AND up.power_type_id = '02' "+filter+" GROUP BY up.unit_id,pb.punish_basis_code ORDER BY up.unit_id DESC";
        List<UnitPower> powers = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> powerGroup = powers.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        List<UnitPower> unitPowers = new ArrayList<>();
        punishGroup.forEach((k, v) -> {
            powerGroup.forEach((p, g) -> {
                if (k.equals(p)) {
                    List<UnitPower> list3 = v.stream()
                            .map(map -> g.stream()
                                    .filter(m -> Objects.equals(m.getPunishBasisCode(), map.getPunishBasisCode()))
                                    .findFirst().map(m -> map).orElse(null))
                            .filter(Objects::nonNull).collect(Collectors.toList());
                    unitPowers.addAll(list3);
                }
            });
        });
        returnMap.put("authority",powerCount);
        returnMap.put("sum",unitPowers.size());
        return returnMap;
    }

    @Override
    public List<Map<String, Object>> getPerformDomain(String start, String end, Long regionid, Integer recType) {
        UnitInfo unit = unitInfoMapper.selectByPrimaryKey(regionid == null ? 1 : regionid);
        List<Map<String, Object>> returnList = new ArrayList<>();
        if (unit == null){
            return returnList;
        }
        //已履行职权信息(统计类别为行政处罚、行政强制)
        String powerFulfilSql = "SELECT rp.subject_id AS  unit_id,rc.punish_basis_code FROM  punish.rec_punish rp LEFT JOIN punish.rec_cause rc ON rp.rec_id = rc.rec_id  WHERE  " +
                "rc.punish_basis_code IN (SELECT  punish_basis_code FROM(  SELECT t1.unit_name,t2.punish_basis_code,t1.unit_id,t3.unit_code  FROM unit_power t1,  " +
                "(SELECT power_id,  punish_basis_code FROM  power_basis  WHERE  cause_id IS NOT NULL  GROUP BY  punish_basis_code  ) t2,  unit_info t3 WHERE  t1.power_id = t2.power_id AND t3.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "  AND t1.power_type_id = '02'  AND t3.unit_id = t1.unit_id  ) t ORDER BY punish_basis_code)  " +
                " AND rp.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "GROUP BY rp.unit_id,rc.punish_basis_code";
        List<UnitPower> list = jdbcTemplate.query(powerFulfilSql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> punishGroup = list.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        // 取出所有unit_id
        List<Long> unitIdList = list.stream().map(UnitPower::getUnitId).distinct().collect(Collectors.toList());
        String filter = "AND up.unit_id in  ('" + StringUtils.join(unitIdList, "','") + "')";
        String sql = "SELECT up.unit_id,pb.punish_basis_code,ud.domain_type_name FROM unit_power up  LEFT JOIN power_basis pb ON up.power_id = pb.power_id  LEFT JOIN unit_info ui ON up.unit_id = ui.unit_id LEFT JOIN unit_domain ud ON ui.unit_id = ud.unit_id WHERE pb.cause_id IS NOT NULL  AND up.power_type_id = '02' "+filter+" GROUP BY up.unit_id,pb.punish_basis_code ORDER BY up.unit_id DESC";
        List<UnitPower> powers = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> powerGroup = powers.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        List<Map<String,Object>> unitPowers = new ArrayList<>();
        punishGroup.forEach((k, v) -> {
            powerGroup.forEach((p, g) -> {
                if (k.equals(p)) {
                    List<Map<String, Object>> list3 = v.stream()
                            .map(map -> g.stream()
                                    .filter(m -> Objects.equals(m.getPunishBasisCode(), map.getPunishBasisCode()))
                                    .findFirst().map(m -> {
                                        Map<String,Object> objectMap = new HashMap<>();
                                        objectMap.put("domain_type_name",m.getDomainTypeName());
                                        objectMap.put("unit_id",map.getUnitId());
                                        objectMap.put("count",1);
                                        return objectMap;
                                    }).orElse(null))
                            .filter(Objects::nonNull).collect(Collectors.toList());
                    unitPowers.addAll(list3);
                }
            });
        });

        returnList = unitPowers.stream().collect(Collectors.groupingBy(e -> e.get("domain_type_name")))
                .entrySet().stream().map(e -> {
                    Map<String, Object> map = new HashMap<>();
                    map.put("timeRange", e.getKey());
                    map.put("count", e.getValue().size());
                    map.put("punish_basis_code", e.getValue());
                    return map;
                }).collect(Collectors.toList());

        return returnList;
    }

    @Override
    public List<Map<String, Object>> getLegalCaseInfo(String start, String end, Long regionid, Integer type, Integer recType) {
        //
        UnitInfo unit = unitInfoMapper.selectByPrimaryKey(regionid == null?1:regionid);
        List<Map<String, Object>> result = new ArrayList<>();
        if (unit == null){
            return result;
        }
        String typeFilter = "";
        if (type.equals(SELECT_DAY)) {
            typeFilter = "DATE_FORMAT(rp.create_time,'%m-%d') AS create_time";
        }else if (type.equals(SELECT_MONTH)){
            typeFilter = "DATE_FORMAT(rp.create_time,'%Y-%m') AS create_time";
        }else if (type.equals(SELECT_WEEK)){
            typeFilter = "DATE_FORMAT(rp.create_time,'%Y-%m') AS create_time";
        }
        //已履行职权信息(统计类别为行政处罚、行政强制)
        String powerFulfilSql = "SELECT rp.subject_id AS  unit_id,rc.punish_basis_code ,"+typeFilter+" FROM  punish.rec_punish rp LEFT JOIN punish.rec_cause rc ON rp.rec_id = rc.rec_id  WHERE  " +
                "rc.punish_basis_code IN (SELECT  punish_basis_code FROM(  SELECT t1.unit_name,t2.punish_basis_code,t1.unit_id,t3.unit_code  FROM unit_power t1,  " +
                "(SELECT power_id,  punish_basis_code FROM  power_basis  WHERE  cause_id IS NOT NULL  GROUP BY  punish_basis_code  ) t2,  unit_info t3 WHERE  t1.power_id = t2.power_id AND t3.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "  AND t1.power_type_id = '02'  AND t3.unit_id = t1.unit_id  ) t ORDER BY punish_basis_code)  " +
                " AND rp.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "GROUP BY rp.unit_id,rc.punish_basis_code";
        List<UnitPower> list = jdbcTemplate.query(powerFulfilSql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> punishGroup = list.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        // 取出所有unit_id
        List<Long> unitIdList = list.stream().map(UnitPower::getUnitId).distinct().collect(Collectors.toList());
        String filter = "AND up.unit_id in  ('" + StringUtils.join(unitIdList, "','") + "')";
        String unitCodeFilter;
        if (!unit.getUnitCode().equals("/1/")) {
            unitCodeFilter = " ui.region_code";
        } else {
            unitCodeFilter = " LEFT (ui.region_code, 4) AS region_code";
        }
        String sql = "SELECT up.unit_id,pb.punish_basis_code,"+unitCodeFilter+" FROM unit_power up  LEFT JOIN power_basis pb ON up.power_id = pb.power_id  LEFT JOIN unit_info ui ON up.unit_id = ui.unit_id WHERE pb.cause_id IS NOT NULL  AND up.power_type_id = '02' "+filter+" GROUP BY up.unit_id,pb.punish_basis_code ORDER BY up.unit_id DESC";
        List<UnitPower> powers = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> powerGroup = powers.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        List<Map<String,Object>> unitPowers = new ArrayList<>();
        punishGroup.forEach((k, v) -> {
            powerGroup.forEach((p, g) -> {
                if (k.equals(p)) {
                    List<Map<String, Object>> list3 = v.stream()
                            .map(map -> g.stream()
                                    .filter(m -> Objects.equals(m.getPunishBasisCode(), map.getPunishBasisCode()))
                                    .findFirst().map(m -> {
                                        Map<String,Object> objectMap = new HashMap<>();
                                        objectMap.put("createTime",map.getCreateTime());
                                        objectMap.put("count",1);
                                        return objectMap;
                                    }).orElse(null))
                            .filter(Objects::nonNull).collect(Collectors.toList());
                    unitPowers.addAll(list3);
                }
            });
        });
         result = unitPowers.stream().collect(Collectors.groupingBy(e -> e.get("createTime")))
                .entrySet().stream().map(e -> {
                    Map<String, Object> map = new HashMap<>();
                    map.put("timeRange", e.getValue().get(0).get("createTime"));
                    final Integer[] i = {0};
                    if (e.getValue().size()>1){
                        e.getValue().forEach(v->{
                            i[0] += v.get("count")==null?0:Integer.parseInt(v.get("count").toString());
                        });
                        map.put("count", i[0]);
                    }else {
                        map.put("count", 0);
                    }
                    return map;
                }).collect(Collectors.toList());
        return result;
    }

    @Override
    public List<Map<String, Object>> getLawCaseTop(String start, String end, Long regionid) {
        //
        UnitInfo unit = unitInfoMapper.selectByPrimaryKey(regionid == null?1:regionid);
        List<Map<String, Object>> result = new ArrayList<>();
        if (unit == null){
            return result;
        }
        //已履行职权信息(统计类别为行政处罚、行政强制)
        String powerFulfilSql = "SELECT rp.subject_id AS  unit_id,rc.punish_basis_code ,rc.law_title FROM  punish.rec_punish rp LEFT JOIN punish.rec_cause rc ON rp.rec_id = rc.rec_id  WHERE  " +
                "rc.punish_basis_code IN (SELECT  punish_basis_code FROM(  SELECT t1.unit_name,t2.punish_basis_code,t1.unit_id,t3.unit_code  FROM unit_power t1,  " +
                "(SELECT power_id,  punish_basis_code FROM  power_basis  WHERE  cause_id IS NOT NULL  GROUP BY  punish_basis_code  ) t2,  unit_info t3 WHERE  t1.power_id = t2.power_id AND t3.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "  AND t1.power_type_id = '02'  AND t3.unit_id = t1.unit_id  ) t ORDER BY punish_basis_code)  " +
                " AND rp.unit_code LIKE  '" +  unit.getUnitCode() + "%'" +
                "GROUP BY rp.unit_id,rc.punish_basis_code";
        List<UnitPower> list = jdbcTemplate.query(powerFulfilSql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> punishGroup = list.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        // 取出所有unit_id
        List<Long> unitIdList = list.stream().map(UnitPower::getUnitId).distinct().collect(Collectors.toList());
        String filter = "AND up.unit_id in  ('" + StringUtils.join(unitIdList, "','") + "')";
        String unitCodeFilter;
        if (!unit.getUnitCode().equals("/1/")) {
            unitCodeFilter = " ui.region_code";
        } else {
            unitCodeFilter = " LEFT (ui.region_code, 4) AS region_code";
        }
        String sql = "SELECT up.unit_id,pb.punish_basis_code,"+unitCodeFilter+" FROM unit_power up  LEFT JOIN power_basis pb ON up.power_id = pb.power_id  LEFT JOIN unit_info ui ON up.unit_id = ui.unit_id WHERE pb.cause_id IS NOT NULL  AND up.power_type_id = '02' "+filter+" GROUP BY up.unit_id,pb.punish_basis_code ORDER BY up.unit_id DESC";
        List<UnitPower> powers = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(UnitPower.class));
        Map<Long, List<UnitPower>> powerGroup = powers.stream().collect(Collectors.groupingBy(UnitPower::getUnitId));
        List<Map<String,Object>> unitPowers = new ArrayList<>();
        punishGroup.forEach((k, v) -> {
            powerGroup.forEach((p, g) -> {
                if (k.equals(p)) {
                    List<Map<String, Object>> list3 = v.stream()
                            .map(map -> g.stream()
                                    .filter(m -> Objects.equals(m.getPunishBasisCode(), map.getPunishBasisCode()))
                                    .findFirst().map(m -> {
                                        Map<String,Object> objectMap = new HashMap<>();
                                        objectMap.put("lawTitle",map.getLawTitle());
                                        objectMap.put("count",1);
                                        return objectMap;
                                    }).orElse(null))
                            .filter(Objects::nonNull).collect(Collectors.toList());
                    unitPowers.addAll(list3);
                }
            });
        });
         result = unitPowers.stream().collect(Collectors.groupingBy(e -> e.get("lawTitle")))
                .entrySet().stream().map(e -> {
                    Map<String, Object> map = new HashMap<>();
                    map.put("lawtitle", e.getValue().get(0).get("lawTitle"));
                    final Integer[] i = {0};
                    if (e.getValue().size()>0){
                        e.getValue().forEach(v->{
                            i[0] += v.get("count")==null?0:Integer.parseInt(v.get("count").toString());
                        });
                        map.put("count", i[0]);
                    }else {
                        map.put("count", 0);
                    }
                    return map;
                }).collect(Collectors.toList());
        List<Map<String, Object>> returnList = result.stream().filter(vo-> !Objects.equals(vo.get("count").toString(), "0")).collect(Collectors.toList());
        return returnList;
    }

    private String regionIdFormat(String regionId) {
        int n = 6;
        if (StringUtils.isNotBlank(regionId) && regionId.length()<n){
            return regionId+String.format("%1$0"+(n-regionId.length())+"d",0);
        }
        return regionId;
    }
    private UnitInfo getRegionInfo(String regionCode) {
        Example example = new Example(UnitInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("unitTypeId", 0);
        criteria.andEqualTo("regionCode", regionCode);
        UnitInfo unitInfo =  unitInfoMapper.selectByExample(example).get(0);
        return unitInfo;
    }
    private static Map<String,Object> objectToMap(Object o) throws IllegalAccessException {
        if(null == o){
            return null;
        }
        Map<String,Object> map = new HashMap<>();
        Field[] declaredFields = o.getClass().getDeclaredFields();
        for (Field field :declaredFields) {
            // （此处如果不设置 无法获取对象的私有属性）
            field.setAccessible(true);
            map.put(field.getName(),field.get(o));
        }
        return map;
    }
}
